package com.server.file.controller.feign;

import com.server.common.code.utils.ResultUtil;
import com.server.model.all.file.vo.UpLoadMainAndThumbnailImageVo;
import com.server.common.code.utils.Result;
import com.server.model.all.enums.BucketNameEnum;
import com.server.model.all.enums.BusinessNameEnum;
import com.server.commons.file.interfaces.FileFactoryInterface;
import com.server.commons.file.model.input.UploadFileInput;
import com.server.common.security.code.anntation.Log;
import com.server.file.service.FileUpLoadService;
import com.server.file.utils.UploadFileInputBuilder;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

@RestController
@RequestMapping(path = "/fileUpLoad/private")
public class FileFeignController {

    @Resource
    private FileFactoryInterface fileFactoryInterface;

    @Resource
    private FileUpLoadService fileUpLoadService;

    /**
     * feign接口调用的
     * @author LXC
     * @date 2022/5/7 23:23
     */
    @Log
    @PostMapping("/upLoadMainAndThumbnailImage")
    public Result<UpLoadMainAndThumbnailImageVo> upLoadMainAndThumbnailImage(@RequestPart("file") MultipartFile multipartFile){
        UploadFileInput uploadFileInput = UploadFileInputBuilder.builder()
                .multipartFile(multipartFile)
                .businessName(BusinessNameEnum.IMAGE)
                .bucketName(BucketNameEnum.MAIN_IMAGE)
                .build();
        return ResultUtil.successData(fileUpLoadService.upLoadMainAndThumbnailImage(uploadFileInput));
    }

}
